﻿/* PictureBox.h
 * 
 * Copyright (C) 2020, 2021 Yuan LI
 * email:18069211@qq.com
 * https://blog.csdn.net/liyuanbhu
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef PICTUREBOX_H
#define PICTUREBOX_H

#include <QWidget>
#include <QImage>
#include <QPixmap>


int namedWindow(QString name, int flag = 0);
int destroyWindow(QString name);
int imshow(QString name, QImage &image);

class PictureBox : public QWidget
{    
    Q_OBJECT
public:
    enum PB_MODE {FIXED_SIZE, FIX_SIZE_CENTRED, AUTO_ZOOM, AUTO_SIZE};
    explicit PictureBox(PB_MODE mode = AUTO_ZOOM, QWidget *parent = 0);
    /**
     * @brief 设置窗口的工作模式
     * @param mode FIXED_SIZE 显示的图像大小等于图像尺寸乘以缩放因子，如果控件的尺寸小于这个大小则多出的部分被裁切掉。
     *             FIX_SIZE_CENTRED 与FIXED_SIZE 模式类似，但是，显示的图像居于窗口正中。
     *             AUTO_ZOOM 显示的图像大小自动适应控件窗口大小。
     *             AUTO_SIZE 控件的尺寸等于图像尺寸乘以缩放因子。
    */
    void setMode(PB_MODE mode);
    ~PictureBox();
private:
    QPixmap m_pixmap;
    double m_scale;
    PB_MODE m_mode;
    QBrush m_brush;
protected:
    void paintEvent(QPaintEvent * event);
signals:

public slots:
    bool setImage(QImage &image, double scale = 1.0);
    void setBackground(QBrush brush);
};

#endif // PICTUREBOX_H
